package com.luxury.fragment.sellementcenter_fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.luxury.R;

import butterknife.BindView;
import butterknife.ButterKnife;

import static android.content.ContentValues.TAG;
import static com.luxury.R.id.tv_cancel_dispatch;

/**
 * A simple {@link Fragment} subclass.
 */
public class DispatchFragment extends Fragment {
    @BindView(R.id.btn_sure_dipatch)
    Button btn_Sure;//确定按钮
    @BindView(R.id.layout_productShow_dipatchFragment)
    LinearLayout layout_ProductShow;//显示商品的横向线性布局
    @BindView(R.id.rbtn_express_dispatch)
    RadioButton rbtn_Express;
    @BindView(R.id.rbtn_self_dispatch)
    RadioButton rbtn_Self;
    @BindView(R.id.rg_dispatchFragment)
    RadioGroup rg_DispatchFragment;
    @BindView(R.id.tv_address_diapath)
    TextView tv_Address;//选择自提的时候 显示选择自提的地址
    @BindView(R.id.tv_time_diapath)
    TextView tv_Time;//选择自提的时候 显示营业时间
    @BindView(R.id.tv_phoneNumber_diapath)
    TextView tv_PhoneNumber;//选择自提的时候 显示贵宾专线
    @BindView(R.id.tv_frontMoney_diapath)
    TextView tv_FrontMoney;//选择自提的时候 显示提示  自提尾款
    @BindView(R.id.layout_self_dispatchFragment)
    LinearLayout layout_Self;//选择自提的时候出来的布局
    @BindView(tv_cancel_dispatch)
    TextView tv_Cancel;
    @BindView(R.id.tv_beijing_dispatch)
    TextView tv_Beijing;//北京地址
    @BindView(R.id.tv_shanghai_dispatch)
    TextView tv_Shanghai;//上海地址
    @BindView(R.id.tv_chengdu_dispatch)
    TextView tv_Chengdu;//成都地址
    @BindView(R.id.layout_self_dispatch)
    RelativeLayout layout_Slef_Amina;//选择自提时候出现显示三个地址的布局 带取消按钮
    private Context mContext = null;
    public DispatchFragment() {
        // Required empty public constructor
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        //得到数据的传输   产品  数量等等
        mContext = context;
    }

    public static DispatchFragment newInstance() {
        Bundle args = new Bundle();
        DispatchFragment fragment = new DispatchFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
            savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dispatch, container, false);
        ButterKnife.bind(this, view);
        //给radioGroup设置监听
        rg_DispatchFragment.setOnCheckedChangeListener(new ChangeListener());
        //点击取消的监听事件
        tv_Cancel.setOnClickListener(new ClickListener());
        tv_Beijing.setOnClickListener(new ClickListener());
        tv_Shanghai.setOnClickListener(new ClickListener());
        tv_Chengdu.setOnClickListener(new ClickListener());
        //点击确定的监听事件
        btn_Sure.setOnClickListener(new ClickListener());
        rbtn_Self.setOnClickListener(new ClickListener());
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    class ClickListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.tv_cancel_dispatch:
                    layout_Slef_Amina.startAnimation(AnimationUtils.loadAnimation(mContext, R
                            .anim.translate_buyproduct_gone));
                    layout_Slef_Amina.setVisibility(View.GONE);
                    btn_Sure.setVisibility(View.VISIBLE);
                    layout_Self.setVisibility(View.GONE);
                    rbtn_Express.setChecked(true);
                    break;
                case R.id.btn_sure_dipatch:
                    Toast.makeText(mContext, "确定了!!!!!!", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.tv_beijing_dispatch:
                    if (layout_Self.getVisibility() == View.GONE) {
                        Toast.makeText(mContext, "诶我去 北京奥", Toast.LENGTH_SHORT).show();
                        layout_Self.setVisibility(View.VISIBLE);
                        Log.i(TAG, "北京你走没??");
                    }
                    tv_Address.setText("自提地址:    北京东城区金宝街18-8号");
                    tv_Time.setText("营业时间:    10:00-21:00");
                    tv_PhoneNumber.setText("贵宾专线:    010-65287779");
                    layout_Slef_Amina.startAnimation(AnimationUtils.loadAnimation(mContext, R
                            .anim.translate_buyproduct_gone));
                    layout_Slef_Amina.setVisibility(View.GONE);
                    btn_Sure.setVisibility(View.VISIBLE);
                    break;
                case R.id.tv_shanghai_dispatch:
                    if (layout_Self.getVisibility() == View.GONE) {
                        Toast.makeText(mContext, "诶我去 上海奥", Toast.LENGTH_SHORT).show();
                        layout_Self.setVisibility(View.VISIBLE);
                        Log.i(TAG, "上海你走没??");
                    }
                    tv_Address.setText("自提地址:    上海市静安区南京西路758号汇银大厦3F");
                    tv_Time.setText("营业时间:    10:00-21:00");
                    tv_PhoneNumber.setText("贵宾专线:    021-62627779");
                    layout_Slef_Amina.startAnimation(AnimationUtils.loadAnimation(mContext, R
                            .anim.translate_buyproduct_gone));
                    layout_Slef_Amina.setVisibility(View.GONE);
                    btn_Sure.setVisibility(View.VISIBLE);
                    break;
                case R.id.tv_chengdu_dispatch:
                    if (layout_Self.getVisibility() == View.GONE) {
                        Toast.makeText(mContext, "诶我去 成都奥", Toast.LENGTH_SHORT).show();
                        layout_Self.setVisibility(View.VISIBLE);
                        Log.i(TAG, "成都你走没??");
                    }
                    tv_Address.setText("自提地址:    成都市人民南路111号航天科技大厦3层");
                    tv_Time.setText("营业时间:    10:00-21:00");
                    tv_PhoneNumber.setText("贵宾专线:    028-65111118");
                    layout_Slef_Amina.startAnimation(AnimationUtils.loadAnimation(mContext, R
                            .anim.translate_buyproduct_gone));
                    layout_Slef_Amina.setVisibility(View.GONE);
                    btn_Sure.setVisibility(View.VISIBLE);
                    break;
                case R.id.rbtn_self_dispatch:
                    layout_Slef_Amina.setVisibility(View.VISIBLE);
                    layout_Slef_Amina.startAnimation(AnimationUtils.loadAnimation(mContext, R
                            .anim.translate_buyproduct));
                    btn_Sure.setVisibility(View.GONE);
                    break;

            }
        }
    }

    class ChangeListener implements RadioGroup.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
            switch (checkedId) {
                case R.id.rbtn_express_dispatch:
                    if (layout_Self.getVisibility() == View.VISIBLE) {
                        layout_Self.setVisibility(View.GONE);
                    }
                    break;
                case R.id.rbtn_self_dispatch:
                    layout_Slef_Amina.setVisibility(View.VISIBLE);
                    layout_Slef_Amina.startAnimation(AnimationUtils.loadAnimation(mContext, R
                            .anim.translate_buyproduct));
                    btn_Sure.setVisibility(View.GONE);
                    break;


            }
        }
    }
}